/*
 * Created by guoyh on Tue Jan 10 2023 22:19:46
 * leetcode NO. 
 */

#include <iostream>
#include <gtest/gtest.h>
#include<regex>
using namespace std;

class Solution {
public:
    bool areNumbersAscending2(string s) {
        regex reg("\\d{1,}");
        vector<int> numbers;
        smatch sm;
        string::const_iterator start = s.begin();
        string::const_iterator end = s.end();

        while(regex_search(start, end, sm, reg)){
            cout<<sm[0]<<endl;
            numbers.push_back(stoi(sm[0]));
            start = sm[0].second;
        }
        if(numbers.size() < 2) 
            return true;

        for(int i = 0, j = 1; j < numbers.size(); i++, j++){
            if(numbers[i] >= numbers[j])
                return false;
        }
        return true;
    }

    bool areNumbersAscending(string s) {
        regex reg("\\d{1,}");
        smatch sm;
        string::const_iterator start = s.begin();
        string::const_iterator end = s.end();
        int pre = INT_MIN;
        int cur = 0;

        while(regex_search(start, end, sm, reg)){
            cur = stoi(sm[0]);
            if(cur <= pre){
                return false;
            }else{
                pre = cur;
            }
            start = sm[0].second;
        }
        
        return true;
    }

    bool isDigit(string s){
        if(s.size() == 0){
            return false;
        }
        for(int i = 0; i < s.size(); i++){
            if(s[i] < '0' || s[i] > '9')
                return false;
        }
        return true;
    }
    
    
};


int add(int a, int b) {
    return a + b;
}

TEST(MyTest, AddTest) {
    EXPECT_EQ(add(1, 2), 3);
}

TEST(MyTest, test01) {
    string s = "box has1 2 3 blue 4 red 6 green and 12 yellow marbles";
    Solution slu;

    EXPECT_EQ(slu.areNumbersAscending(s), true);
}

TEST(MyTest, test02) {
    string s = "box has1 5 3 blue 4 red 6 green and 12 yellow marbles";
    Solution slu;

    EXPECT_EQ(slu.areNumbersAscending(s), false);
}

TEST(MyTest, test03) {
    string s = "box has1 2";
    Solution slu;

    EXPECT_EQ(slu.areNumbersAscending(s), true);
}

TEST(MyTest, test04) {
    string s = "box has3 2";
    Solution slu;

    EXPECT_EQ(slu.areNumbersAscending(s), false);
}

TEST(MyTest, test05) {
    string s = "box has 2";
    Solution slu;

    EXPECT_EQ(slu.areNumbersAscending(s), true);
}

TEST(MyTest, test06) {
    string s = "hello world 5 x 5"; 
    Solution slu;

    // 必须严格递增
    EXPECT_EQ(slu.areNumbersAscending(s), false); 
}

TEST(ISDIGIT_TEST, test01){
    string s("a1");
    Solution slu;
    ASSERT_EQ(slu.isDigit(s), false);
}

TEST(ISDIGIT_TEST, test02){
    string s("231a");
    Solution slu;
    ASSERT_EQ(slu.isDigit(s), false);
}

TEST(ISDIGIT_TEST, test03){
    string s("23");
    Solution slu;
    ASSERT_EQ(slu.isDigit(s), true);
}

TEST(ISDIGIT_TEST, test04){
    string s("");
    Solution slu;
    ASSERT_EQ(slu.isDigit(s), false);
}

int main(int argc, char *argv[]) {
    ::testing::InitGoogleTest(&argc, argv);
    return RUN_ALL_TESTS();
}
